<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #tableBeforeButtons>
        <a-button
          type="primary"
          @click="setFdcc(tab)"
          v-auth="['prediction:order:blth']"
          >生成巡检任务</a-button
        >
      </template>
      <template #operationBeforeExtend="{ record }">
        <a-link @click="handleDetail(record)">详情</a-link>
      </template>
    </ma-crud>
    <!-- 生成巡检 -->
    <a-modal
      v-model:visible="visiblecangcuSL"
      title="生成巡检任务"
      @cancel="visiblecangcuSL = false"
      :width="1200"
      ok-text="确认生成巡检"
      :footer="true"
      @ok="ok()"
    >
      <div style="height: calc(100vh - 200px); overflow: auto">
        <cangcuSL ref="cangcuSLRef" :route_ids="route_ids" @therr="therradd" />
      </div>
    </a-modal>
    <!-- 详情 -->
    <a-drawer :footer="false" :width="1000" v-model:visible="detailShow">
      <template #title> 巡查详情 </template>
      <detailindex v-if="detailShow"  :info="itemDate" />
    </a-drawer>
  </div>
</template>
<script setup>
import { ref, reactive } from "vue";
import secureInpectionDistribute from "@/api/secure/secureInpectionDistribute";
import cangcuSL from "@/views/secure/inspectionrouteManage/infoadd.vue";
import detailindex from "@/views/secure/inpectionDistribute/detail.vue";

import { request } from "@/utils/request.js";
import { Message } from "@arco-design/web-vue";
import tool from "@/utils/tool";
import * as common from "@/utils/common";
import { data } from "@visactor/vtable";

const crudRef = ref();
const visiblecangcuSL = ref(false);
let tab = 1;
const itemDate = ref({})
const detailShow = ref(false)
const cangcuSLRef = ref();
const route_ids = ref([]);
const handleDetail = (row)=>{
  itemDate.value = row
  detailShow.value = true
}
const numberOperation = (newValue, id, numberName) => {
  secureInpectionDistribute
    .numberOperation({ id, numberName, numberValue: newValue })
    .then((res) => {
      res.success && Message.success(res.message);
    })
    .catch((e) => {
      console.log(e);
    });
};
const therradd = (val) => {
  route_ids.value = val;
};
const switchStatus = (statusValue, id, statusName) => {
  secureInpectionDistribute
    .changeStatus({ id, statusName, statusValue })
    .then((res) => {
      res.success && Message.success(res.message);
    })
    .catch((e) => {
      console.log(e);
    });
};

// 生成巡检
const setFdcc = (row) => {
  visiblecangcuSL.value = true;
};

const ok = () => {
  request({
    url: "secure/inpectionDistribute/adds",
    method: "post",
    data: {
      ids: route_ids.value.join(","),
    },
  }).then((res) => {
    Message.success("巡检任务生成成功");
    crudRef.value.refresh();
  });
  return;
};

const options = reactive({
  id: "flyos_secure_inpection_distribute",
  rowSelection: {
    showCheckedAll: true,
  },
  pk: "id",
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: "modal",
    width: 600,
  },
  api: secureInpectionDistribute.getList,
  recycleApi: secureInpectionDistribute.getRecycleList,
  // add: {
  //   show: true,
  //   api: secureInpectionDistribute.save,
  //   auth: ['secure:inpectionDistribute:save']
  // },
  edit: {
    show: true,
    api: secureInpectionDistribute.update,
    auth: ["secure:inpectionDistribute:update"],
  },
  // delete: {
  //   show: true,
  //   api: secureInpectionDistribute.deletes,
  //   auth: ['secure:inpectionDistribute:delete'],
  //   realApi: secureInpectionDistribute.realDeletes,
  //   realAuth: ['secure:inpectionDistribute:realDeletes']
  // },
  recovery: {
    show: true,
    api: secureInpectionDistribute.recoverys,
    auth: ["secure:inpectionDistribute:recovery"],
  },
  import: {
    show: true,
    url: "secure/inpectionDistribute/import",
    templateUrl: "secure/inpectionDistribute/downloadTemplate",
    auth: ["secure:inpectionDistribute:import"],
  },
  export: {
    show: true,
    url: "secure/inpectionDistribute/export",
    auth: ["secure:inpectionDistribute:export"],
  },
});

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入ID",
    },
  },
  {
    title: "路线名称",
    dataIndex: "route_name",
    formType: "input",
    search: true,
  },
  {
    title: "日期",
    dataIndex: "month_time",
    formType: "date",
    search: true,
    showTime: true,
    range: false,
  },
  {
    title: "审批结果",
    dataIndex: "examine_result",
    formType: "radio",
    search: true,
    commonRules: {
      required: true,
      message: "请输入审批结果",
    },
    dict: {
      name: "examine_result",
      props: {
        label: "title",
        value: "key",
      },
      translation: true,
    },
  },
  {
    title: "节点信息",
    dataIndex: "not_node_info",
    formType: "input",
    search: false,
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: false,
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true,
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true,
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true,
  },
]);
</script>
<script>
export default { name: "secure:inpectionDistribute" };
</script>
